package com.market.xg.auth.web.ums;

import com.market.xg.auth.service.ums.UmsAdminService;
import com.market.xg.auth.service.ums.dto.LoginInfoReqDTO;
import com.market.xg.auth.web.ums.vo.LoginInfoReqVO;
import com.market.xg.common.starter.auth.XgAppUser;
import com.market.xg.common.starter.auth.XgPcUser;
import com.market.xg.common.starter.common.CommonResult;
import com.market.xg.common.starter.util.BeanUtils;
import com.market.xg.search.api.goods.GoodsSearchServiceApi;
import com.market.xg.search.api.goods.dto.GoodsSearchDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@Slf4j
@RestController
@Api(tags = "AuthController 认证中心登录认证服务")
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    UmsAdminService umsAdminService;

    @Autowired
    GoodsSearchServiceApi goodsSearchServiceApi;

    @ApiOperation("Oauth2获取App端token")
    @PostMapping(value = "/getAppToken")
    public CommonResult<String> getAppToken(@RequestBody LoginInfoReqVO loginInfoReqVO) {
        LoginInfoReqDTO loginInfoReqDTO = BeanUtils.copy(loginInfoReqVO, LoginInfoReqDTO.class);
        String appToken = umsAdminService.getAppToken(loginInfoReqDTO);
        log.info("getAppToken appToken={}",appToken);
        return CommonResult.success(appToken);
    }

    @ApiOperation("获取PC资源树接口")
    @GetMapping(value = "/getPcResources")
    public void getPcResources(@ApiIgnore XgAppUser xgAppUser) {
        log.info("getPcResources xgPcUser={}",xgAppUser);
        GoodsSearchDTO goodsSearchDTO = new GoodsSearchDTO();
        goodsSearchDTO.setGoodsName("商品名称");
        goodsSearchDTO.setUserCode("用户code");
        String goodsSearch = goodsSearchServiceApi.getGoodsSearch(goodsSearchDTO);
        log.info("getPcResources goodsSearch={}",goodsSearch);
    }

    @ApiOperation("获取PC资源树接口")
    @GetMapping(value = "/getOpenresty")
    public String getPcResources() {
        log.info("getPcResources getOpenresty");
       return goodsSearchServiceApi.testGray();
    }

}
